package com.hzlj.position.locate.differentiation.common;

import cn.hutool.core.util.ObjectUtil;
import com.google.common.collect.Lists;
import com.hzlj.position.config.common.dto.common.PositionHandleExtDTO;
import com.hzlj.position.locate.common.dto.position.PositionHandleDTO;
import com.hzlj.position.locate.common.dto.position.PositionKeyDTO;
import com.hzlj.position.locate.common.enums.PositionSysCheck;
import com.hzlj.position.locate.service.MessageTemplateBussService;
import com.hzlj.position.locate.service.PositionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@Service
public class PositionSysCheckHandle implements MessageTemplateBussService {
    @Resource
    private PositionService positionService;

    public void handleNormal(PositionKeyDTO key,
                             String normalRemark) {
        this.handleNormal(Lists.newArrayList(key), normalRemark);
    }

    public void handleNormal(List<PositionKeyDTO> keys,
                             String normalRemark) {
        if (ObjectUtil.isEmpty(keys)) {
            return;
        }
        //处理
        PositionHandleDTO handle = new PositionHandleDTO();
        handle.setKeys(keys);
        handle.setNormal(true);
        handle.setAutoHandle(true);
        handle.setSysCheck(PositionSysCheck.SUCCESS.getCheck());

        PositionHandleExtDTO ext = new PositionHandleExtDTO();
        ext.setHandleRemark("经核查，矫正对象状态正常，网络问题导致");
        ext.setHandlerUid("system");
        ext.setHandlerName("系统");
        ext.setHandleReason(normalRemark);
        handle.setHandleExt(ext);

        //调用处理
        positionService.handle(handle);
    }

    public void handleAbn(PositionKeyDTO key,
                          String abnRemark) {
        this.handleAbn(Lists.newArrayList(key), abnRemark);
    }

    public void handleAbn(List<PositionKeyDTO> keys,
                          String abnRemark) {
        if (ObjectUtil.isEmpty(keys)) {
            return;
        }
        //处理
        PositionHandleDTO handle = new PositionHandleDTO();
        handle.setKeys(keys);
        handle.setNormal(false);
        handle.setAutoHandle(true);
        handle.setSysCheck(PositionSysCheck.FAIL.getCheck());

        PositionHandleExtDTO ext = new PositionHandleExtDTO();
        ext.setHandleRemark("经核查，矫正对象存在该异常，已教育");
        ext.setHandlerUid("system");
        ext.setHandlerName("系统");
        ext.setHandleReason(abnRemark);
        handle.setHandleExt(ext);

        //调用处理
        positionService.handle(handle);
    }


    public void handleSysCheck(PositionKeyDTO key,
                               PositionSysCheck sysCheck) {
        this.handleSysCheck(Lists.newArrayList(key), sysCheck);
    }


    public void handleSysCheck(List<PositionKeyDTO> keys,
                               PositionSysCheck sysCheck) {
        if (ObjectUtil.isEmpty(keys)) {
            return;
        }
        //处理
        PositionHandleDTO handle = new PositionHandleDTO();
        handle.setKeys(keys);
        handle.setSysCheck(sysCheck.getCheck());

        //调用处理
        positionService.handleSysCheck(handle);
    }


}
